#!/bin/sh
#指定部署目录，拉取git上最新的代码
codePath="/home/tiannianbao/tnb-server/tiannainbao"
homePath="/home/tiannianbao"
shellPath="/home/tiannianbao/tnb-server/tiannainbao/deploy/shell"
target_path="/home/tiannianbao/tnb-server/tiannainbao/target"
publish_path="/home/tiannianbao/tnb-server/tiannainbao/dev-publish"
gitOsc="git@git.oschina.net:huibati/tiannainbao.git"
package_path="/home/tiannianbao/tnb-server/tiannainbao/src/main/resources/"
test_lib_path="/home/tiannianbao/tnb-server/tiannainbao/deploy/env/jujia/"
product_lib_path="/home/tiannianbao/tnb-server/tiannainbao/deploy/env/product/"
application="application.properties"
log4j="log4j.properties"
persistence_mysql="persistence-mysql.properties"
jar_name="tnb-server_test.jar"
publish_lib_path="/home/tiannianbao/tnb-server/tiannainbao/deploy/env/test/"
jujia_lib_path="/home/tiannianbao/tnb-server/tiannainbao/deploy/env/jujia/"
demo_lib_path="/home/tiannianbao/tnb-server/tiannainbao/deploy/env/demo/"
mem_size="512M"
#################################GIT拉取最新代码##################################
echo  "拉取代码..."
git stash save "s"
cd $homePath
if [ ! -d $codePath ]
then
	rm -rf $codePath
	git clone $gitOsc
	git branch product --track origin/product
else
    echo  "拉取代码...1"
	cd $codePath
fi
###################################################################################

#################################选择打包库########################################
echo  "请选择打包库："
read -p  "7080-居家演示库（1）  7070-发布测试库（2）  7060-demo库（3）生产库7090（4）  退出（5）" choic

if [ $choic -eq 1 ]
then
	echo "打包 居家演示库"
	echo "拉取代码"
	git pull
	publish_path="/home/tiannianbao/tnb-server/tiannainbao/dev-publish-7080"
	jar_name="tnb-server_jujia.jar"
	mem_size="256M"
	#拷贝差异化配置文件
	cp $test_lib_path$application $package_path$application
	cp $test_lib_path$log4j $package_path$log4j
	cp $test_lib_path$persistence_mysql $package_path$persistence_mysql
	#打包部署
	source $shellPath/ssh_deploy-23_back_end.sh
elif [ $choic -eq 2 ]
then
	echo "打包发布测试库"
	echo "拉取代码"
	git pull
	publish_path="/home/tiannianbao/tnb-server/tiannainbao/test-publish-7070"
	jar_name="tnb-server_publish.jar"
	echo "publish_path is:"$publish_path
	cp $publish_lib_path$application $package_path$application
	cp $publish_lib_path$log4j $package_path$log4j
	cp $publish_lib_path$persistence_mysql $package_path$persistence_mysql
	source $shellPath/ssh_deploy-23_back_end.sh
elif [ $choic -eq 3 ]
then
	mem_size="256M"
	echo "打包demo库"
	echo "拉取代码"
	git pull
	publish_path="/home/tiannianbao/tnb-server/tiannainbao/demo-7060"
	jar_name="tnb-server_demo.jar"
	echo "publish_path is:"$publish_path
	cp $demo_lib_path$application $package_path$application
	cp $demo_lib_path$log4j $package_path$log4j
	cp $demo_lib_path$persistence_mysql $package_path$persistence_mysql
	source $shellPath/ssh_deploy-23_back_end.sh	
elif [ $choic -eq 4 ]
then
	mem_size="1024M"
	echo "打包生产库"
	echo "拉取代码"
	git pull
	publish_path="/home/tiannianbao/tnb-server/tiannainbao/product-7090"
	jar_name="tnb-server.jar"
	echo "publish_path is:"$publish_path
	cp $product_lib_path$application $package_path$application
	cp $product_lib_path$log4j $package_path$log4j
	cp $product_lib_path$persistence_mysql $package_path$persistence_mysql
	source $shellPath/ssh_deploy-23_back_end.sh	
elif [ $choic -eq 5 ]
then
	exit 0
else
	exit 2
fi
###################################################################################
echo  "ok..."